package csdn.xiancheng.li04;

public class Test {
    public static void main(String[] args) {
        Thread t1=new Thread(){
            @Override
            public void run() {
                for (int i = 1; i < 41; i++) {
                    System.out.println("t1:"+i);
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        Runnable r1=new Runnable() {
            @Override
            public void run() {
                for (int i = 100; i > 69; i--) {
                    //Thread.currentThread().getName();----获取线程名
                    System.out.println("r1:"+i);
               
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            //     //观测join作用
            //   if(i==80){
            //     try {
            //         t1.join();//卡断当前线程，直到另一个指定的线程结束才继续运行,这里卡断了r1，直到t1线程结束r1才能继续运行
            //         System.out.println("join发力");
            //     } catch (InterruptedException e) {
            //         e.printStackTrace();
            //     }
            //   }  
            
                if(i==80){
                    try {
                        t1.join(10);//进入计时等待
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }}
        };
        Thread t2=new Thread(r1);
        t1.start();
        t2.start();
    }
}
